Imports System.IO 
Imports System.Management

Namespace BasicSystem
    ''' <summary>
    ''' Information of System
    ''' </summary>
    ''' <remarks></remarks>
    ''' <create date="2013-05-05">atthapol w.</create>
    Public Class OS

        ''' <summary>
        ''' Determines whether the current operating system is a 64-bit operating system.
        ''' </summary>
        ''' <returns>true if path refers to an existing directory; otherwise, false.</returns>
        ''' <remarks></remarks>
        ''' <create date="2013-05-05">atthapol w.</create>
        Public Shared Function Is64BitOperatingSystem() As Boolean
            Dim strPath As String = Nothing
            Dim isOS64Bit As Boolean = False

            strPath = Environment.GetEnvironmentVariable("ProgramW6432")

            If (strPath IsNot Nothing) AndAlso (strPath.Trim.Length > 0) Then
                'Make sure 64 bits Operating System.
                If Directory.Exists("C:\Program Files (x86)") Then
                    isOS64Bit = True
                End If
            End If

            Return isOS64Bit
        End Function

        ''' <summary>
        ''' Gets the version of the computer's operating system.
        ''' </summary>
        ''' <param name="isVbaCompatible">Boolean of compatible of Visual Basic old version.</param>
        ''' <returns>A String containing the current version number of the operating system.</returns>
        ''' <remarks></remarks>
        Public Function GetVersion(Optional ByVal isVbaCompatible As Boolean = False) As String
            If isVbaCompatible Then
                Dim computer As Microsoft.VisualBasic.Devices.Computer = New Microsoft.VisualBasic.Devices.Computer

                Debug.Print(computer.Info.OSFullName)
                Debug.Print(computer.Info.OSPlatform)
                Debug.Print(computer.Info.OSVersion)

                Return computer.Info.OSVersion

            Else
                Dim osInfo As OperatingSystem = Environment.OSVersion

                Debug.Print(osInfo.Platform.ToString())
                Debug.Print(osInfo.VersionString)

                Return osInfo.VersionString
            End If

        End Function
    End Class

End Namespace

